﻿using System.Collections.Generic;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace PsTFS.Objects.Methodes
{
    /// <summary>
    /// Classe de gestion du workspace
    /// </summary>
    public static partial class Methode
    {
        #region CreateWorkspace

        /// <summary> 
        /// Permet de créer un workspace ou de récupérer le workspace courant
        /// </summary>
        /// <param name="Name">Nom du workspace</param>
        /// <param name="Owner">Propriétaire du workspace</param>
        /// <param name="ServerPath">Emplacement Serveur</param>
        /// <param name="LocalPath">Emplacement local</param>
        /// <returns></returns>
        internal static Workspace CreateWorkspace(string Name, string Owner, string ServerPath, string LocalPath)
        {
            WorkingFolder[] workingFolders = new WorkingFolder[] { new WorkingFolder(ServerPath, LocalPath, WorkingFolderType.Map) };
            return CreateWorkspace(Name, Owner, workingFolders);
        }

        internal static Workspace CreateWorkspace(string Name, string Owner, WorkingFolder[] workingFolders)
        {
            //Récupération du workspace
            Workspace workspace = Context.GetContext().Workspace;
            // Mapping du projet et du répertoire. 
            workspace.Update(Name, null, workingFolders);

            return workspace;
        }

        #endregion CreateWorkspace

        /// <summary>
        /// Permet de récupérer un workspace
        /// </summary>
        /// <param name="Name">Nom</param>
        /// <param name="Owner">Propritaire</param>
        /// <returns>Retourne le workspace</returns>
        public static Workspace GetWorkspace(string Name, string Owner)
        {
            // Récupération du Version Control. 
            VersionControlServer versionControl = Methode_Service.VCS();
            return versionControl.GetWorkspace(Name, Owner);
        }

        /// <summary>
        /// Permet de récupérer l'ensemble des workspace
        /// </summary>
        /// <returns></returns>
        public static List<Workspace> GetAllWorkspace()
        {
            // Récupération du Version Control. 
            VersionControlServer versionControl = Methode_Service.VCS();
            Workspace[] ws = versionControl.QueryWorkspaces(null, null, null);
            return new List<Workspace>(ws);

        }

    }
}
